package com.zhongyu.controller;

import com.zhongyu.pojo.CangkuKucun;
import com.zhongyu.pojo.Goods;
import com.zhongyu.pojo.OrderDetail;
import com.zhongyu.pojo.User;
import com.zhongyu.service.GoodsService;
import com.zhongyu.service.KuCunService;
import com.zhongyu.vo.GoodsVo;
import com.zhongyu.vo.KuCunVo;
import com.zhongyu.vo.PageResult;
import com.zhongyu.vo.ResultVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
/*
库存
 */
@RestController
@RequestMapping("/kucun/ckkc")
public class kuCunController {
    @Resource
    private KuCunService kuCunService;
    @GetMapping("/search/{pageNo}/{pageSize}")
    public ResultVo search(@PathVariable Integer pageNo, @PathVariable Integer pageSize, KuCunVo kuCunVo){
        PageResult pageResult=kuCunService.searchAll(pageNo,pageSize,kuCunVo);
        return ResultVo.success(pageResult);

    }
    @GetMapping("/list")
    public ResultVo list() {
        List<CangkuKucun> list = kuCunService.searchAll();
        return ResultVo.success(list);

    }
    @PostMapping("/zhuanku")
    public ResultVo zhuanku(@RequestBody CangkuKucun cangkuKuCun,Integer cangkuId, Integer shuliang, Integer goodsId,HttpSession session) {
        try {
            User loginUser = (User) session.getAttribute("loginUser");
            return kuCunService.zhuankuStore(cangkuKuCun,loginUser.getId(), cangkuId, goodsId,shuliang);
        } catch (Exception e) {
            return ResultVo.failure("转库失败", e);
        }
    }

}
